/**
 * @file 错误拦截中间件
 */
import { MiddlewareFunction } from "../../index.d.js"

/** 错误拦截中间件 */
export const errorMiddleware: MiddlewareFunction = ({ response }, next) => {
  try {
    next()
  } catch (err) {
    response.setHeader("Content-Type", "text/plain;charset=utf-8")
    response.statusCode = 500
    response.end("系统错误")
  }
}
